{include file="public/layout" /}
<body class="laytp-container">
<div class="layui-card" >
    <div class="layui-card-body">
        <div class="layui-card-header">
            <i class="fa fa-pencil"></i> 编辑
        </div>
        <form class="layui-form" action="">
            <input type="hidden" name="template_id" value="{$info.template_id}" />
            <div class="layui-form-item">
                <label class="layui-form-label">配送方式：</label>
                <div class="layui-input-inline" style="width:500px">
                    <input type="radio" name="pstype" value="0" title="普通快递" {if !$info || !$info['template_id'] || $info['pstype']==0}checked{/if} lay-filter="pstype">
                    <input type="radio" name="pstype" value="1" title="到店自提" {if $info && $info['pstype']==1}checked{/if} lay-filter="pstype">
                    <input type="radio" name="pstype" value="2"  title="同城配送" {if $info && $info['pstype']==2}checked{/if} lay-filter="pstype">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">模板名称：</label>
                <div class="layui-input-inline">
                    <input type="text" name="template_name" value="{if !$info || !$info['template_id']}普通快递{else}{$info['template_name']}{/if}" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div id="peisong_kuaidi" {if $info && $info['pstype']!=0}style="display:none;"{/if}>
                {include file="freight/edit_kuaidi" /}
            </div>
            <div id="peisong_ziti" {if !$info || $info['pstype']!=1}style="display:none;"{/if}>
                {include file="freight/edit_ziti" /}
            </div>
            <div id="peisong_peisong" {if !$info || $info['pstype']!=2}style="display:none;"{/if}>
                {include file="freight/edit_peisong" /}
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">序号：</label>
                <div class="layui-input-inline">
                    <input type="text" name="sort"   value="{$info.sort|default=0}" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">用于排序,越大越靠前</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">状态：</label>
                <div class="layui-input-inline">
                    <input type="radio" name="status"   value="1" title="开启" {if !$info || !$info['template_id'] || $info['status']==1}checked{/if}>
                    <input type="radio" name="status"   value="0" title="关闭" {if $info && $info['template_id'] && $info['status']==0}checked{/if}>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">确认</button>
                </div>
            </div>
        </form>
    </div>
</div>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script>
    layui.use(['form', 'laydate', 'util'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;

        // 自定义验证规则
        form.verify({
            pass: [
                /^[\S]{6,12}$/,
                '密码必须6到12位，且不能出现空格'
            ]
        });

        // 提交事件
        form.on('submit(demo1)', function(data){
            var index = layer.load();
            layer.close(index);

            var field = data.field; // 获取表单字段值
            $.ajax({
                type: "POST",
                url: "{:url('save')}",
                data: field,
                success: function(res){
                    console.log(res);
                    if(res.status){
                        layer.msg('提交成功');
                    }else{
                        layer.msg(res.msg);
                    }
                    setTimeout(function(){
                        parent.layer.closeAll();
                        parent.tableIns.reload()
                    },1000)
                }
            });
            return false; // 阻止默认 form 跳转
        });

        // 日期
        laydate.render({
            elem: '#date'
        });
    });
    layui.form.on('radio(pstype)',function(data){
        if(data.value == '0'){
            $('#peisong_kuaidi').show();
            $('#peisong_ziti').hide();
            $('#peisong_peisong').hide();
        }else if(data.value == '1'){
            $('#peisong_kuaidi').hide();
            $('#peisong_ziti').show();
            $('#peisong_peisong').hide();
        }if(data.value == '2'){
            $('#peisong_kuaidi').hide();
            $('#peisong_ziti').hide();
            $('#peisong_peisong').show();
        }
    })
</script>
</body>
</html>